home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH06 / PGM6_9.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-10  |  1.8 KB  |  111 lines

  1. ; Conditional JMP Instructions, Part I
  2.  
  3.         .386
  4.         option    segment:use16
  5. dseg        segment    para public 'data'
  6. J        sword    ?
  7. K        sword    ?
  8. L        sword    ?
  9. dseg        ends
  10.  
  11. cseg        segment    para public 'code'
  12.         assume    cs:cseg, ds:dseg
  13.  
  14. Main        proc
  15.         mov    ax, dseg
  16.         mov    ds, ax
  17.         mov    es, ax
  18.  
  19. ; 8086 conditional jumps are limited to
  20. ; +/- 128 bytes because they are only
  21. ; two bytes long (one byte opcode, one
  22. ; byte displacement).
  23.  
  24.         .8086
  25.         ja    lbl
  26.         nop
  27. lbl:
  28.  
  29. ; MASM 6.x will automatically extend out of
  30. ; range jumps.  The following are both
  31. ; equivalent:
  32.  
  33.         ja    lbl2
  34.         byte    150 dup (0)
  35. lbl2:
  36.         jna    Temp
  37.         jmp    lbl3
  38. Temp:
  39.         byte    150 dup (0)
  40. lbl3:
  41.  
  42.  
  43. ; The 80386 and later processors support a
  44. ; special form of the conditional jump
  45. ; instructions that allow a two-byte displace-
  46. ; ment, so MASM 6.x will assemble the code
  47. ; to use this form if you've specified an
  48. ; 80386 processor.
  49.  
  50.         .386
  51.         ja    lbl4
  52.         byte    150 dup (0)
  53. lbl4:
  54.  
  55. ; The conditional jump instructions work
  56. ; well with the CMP instruction to let you
  57. ; execute certain instruction sequences
  58. ; only if a condition is true or false.
  59. ;
  60. ; if (J <= K) then
  61. ;    L := L + 1
  62. ; else  L := L - 1
  63.  
  64.         mov    ax, J
  65.         cmp    ax, K
  66.         jnle    DoElse
  67.         inc    L
  68.         jmp    ifDone
  69.  
  70. DoElse:        dec    L
  71. ifDone:
  72.  
  73. ; You can also use a conditional jump to
  74. ; create a loop in an assembly language
  75. ; program:
  76. ;
  77. ; while (j >= k) do begin
  78. ;
  79. ;    j := j - 1;
  80. ;    k := k + 1;
  81. ;    L := j * k;
  82. ; end;
  83.  
  84. WhlLoop:    mov    ax, j
  85.         cmp    ax, k
  86.         jnge    QuitLoop
  87.  
  88.         dec    j
  89.         inc    k
  90.         mov    ax, j
  91.         imul    ax, k
  92.         mov    L, ax
  93.         jmp    WhlLoop
  94.  
  95. QuitLoop:
  96.  
  97. Quit:        mov    ah, 4ch            ;DOS opcode to quit program.
  98.         int    21h            ;Call DOS.
  99. Main        endp
  100.  
  101. cseg        ends
  102.  
  103. sseg        segment    para stack 'stack'
  104. stk        byte    1024 dup ("stack   ")
  105. sseg        ends
  106.  
  107. zzzzzzseg    segment    para public 'zzzzzz'
  108. LastBytes    byte    16 dup (?)
  109. zzzzzzseg    ends
  110.         end    Main
  111.